<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
  <el-container>
    <el-header style="background-color: #0095d7">
      <h1 style="color: white;font-size: 22px">
        bookshop书城后台管理系统
        <span v-if="user.name!=null"
              style="float: right;font-size: 15px">欢迎{{user.name}}回来
                    <a href="javascript:void(0)" @click="logout()" >退出登录</a>
                </span>
      </h1>
    </el-header>
    <el-container>
      <el-aside width="200px" style="overflow:hidden;">
        <!--导航菜单开始-->
        <el-menu @select="handleSelect">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-s-flag"></i>
              <span>书籍管理</span>
            </template>
            <el-menu-item index="1-1">分类列表</el-menu-item>
            <el-menu-item index="1-2">添加分类</el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-picture"></i>
              <span>轮播图管理</span>
            </template>
            <el-menu-item index="2-1">轮播图列表</el-menu-item>
            <el-menu-item index="2-2">添加轮播图</el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-shopping-cart-2"></i>
              <span>商品管理</span>
            </template>
            <el-menu-item index="3-1">书籍列表</el-menu-item>
            <el-menu-item index="3-2">添加书籍</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

    </el-container>
  </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
  let v = new Vue({
    el: '#app',
    data: function (){
      return{
        user:{}
      }
    },
    methods: {
      logout() {
        if (confirm("您确认退出登录吗?")) {
          //发出退出登录请求
          axios.get("/logout").then(function () {
            location.href = "/";
          })
        }
      },
      handleSelect(key,keyPath){
        if (key=="1-2"){
          let name = prompt("请输入添加分类的名称");
          console.log("分类名:"+name);
          if (name==null){return;}
          if (name.trim()==""){
            v.$message.error("请输入分类名称!")
            return;
          }
          axios.get("/category/insert?name="+name).then(function (response) {
            v.$message.success("添加完成!");
            v.categoryArr = response.data;
          })}else{
          v.currentIndex = key;
        }
      }
    },
    created:function () {
      axios.get("/getUserType").then(function (response) {
        this.user = response.data();
      })
    }
  })
</script>
</html>